package org.shangrila.app.sys.shiro;

import java.util.List;

import org.shangrila.app.sys.eo.SysUser;
import org.shangrila.comm.dao.DbAccess;

public class AppShiroDao {

	private DbAccess dbAccess = new DbAccess();
	public DbAccess getDbAccess() {		return dbAccess;	}
	
	public static final String SysUser_findAll="SELECT s FROM SysUser s";
	public static final String SysUser_findByUserno="SELECT s FROM SysUser s WHERE s.userno=?1";
	public static final String SysUser_findByEmail="SELECT s FROM SysUser s WHERE s.email=?1";
	public static final String SysUser_findByUsernoPassword="SELECT s FROM SysUser s WHERE s.userno=?1 and s.password=?2";
	public static final String SysUser_findByOrgID="SELECT s FROM SysUser s WHERE s.sysOrganization.id=?1";
	
	//find SysUser
	/*
	@SuppressWarnings("unchecked")
	public List<SysUser> findSysUserAll() {
		return (List<SysUser>) dbAccess.createQuery(SysUser_findAll).getResultList();
	}
	*/
	public List<SysUser> findSysUserAll() {
		return dbAccess.findBySql(SysUser_findAll, true);
	}
	
	
	@SuppressWarnings("unchecked")
	public List<SysUser> findSysUserByOrgID(String orgid) {
		return (List<SysUser>) dbAccess.createQuery(SysUser_findByOrgID).setParameter(1, orgid).getResultList();
	}

	public SysUser findSysUserByUserno(String userno) {
		return (SysUser) dbAccess.createQuery(SysUser_findByUserno).setParameter(1, userno).getSingleResult();
	}
	public SysUser findSysUserByEmail(String email) {
		return (SysUser) dbAccess.createQuery(SysUser_findByEmail).setParameter(1, email).getSingleResult();
	}
	public SysUser findSysUserByUsernoPassword(String userno,String password) {
		return (SysUser) dbAccess.createQuery(SysUser_findByUsernoPassword).setParameter(1, userno).setParameter(2, password).getSingleResult();
	}

	
}
